<script type="text/javascript">
$(function () {
	var pg = App.sequence.infoIndex.ui, pp = pg.params,
		naviName = pg.children('.navi').seek('title');
	naviName.text('全部序列');
	var gd = pg.find('.grid').mac('grid', {
		key: 'id',
		cols: [{
			field: 'catalog', title : '所属系统', width: 120,
			render: function(r, tr, me){
				return $('<span class="a"></span>').click(function(){
					me.load({ catalog: r.catalog, pageNo: 1, key: '' });
				}).append(r.catalog);
			}
		},{
			field: 'code', title : '编号', width: 160,
			render: function(r, tr, me){
				return $('<span class="a"></span>').click(function(){
						App.show({
							title:'序列修改',
							ctx : 'sequence',
							action : 'infoEdit',
							params : r
						}, $.noop, pg.parent());
				}).append(r.code);
			}
		},{
			field: 'name', title : '名称', width: 160
		},{
			field: 'type', title : '类型', width: 60,
			
			render:function (r,tr,gd) {
				var p = $('<div></div>'), v = r.type;
				
				if(r.type==0){
					//分段序列
					return $('<span class="a"></span>').click(function(){
						if (App.logon.power('sequence.segment.list')){
							App.show({
								title:'号段',
								ctx : 'sequence',
								action : 'segmentIndex',
								params : r
							}, $.noop, pg.parent());
						}
					}).append(Cache.sequence.type[r.type]);
				}
				return p.text(Cache.sequence.type[r.type]);
				
				 
			}
		},{
			field: 'segLen', title : '长度', width: 60
		},{
			field: 'beginNo', title : '起始值', width: 120
		},{
			field: 'endNo', title : '结束值', width: 120
		},{
			field: 'currentNo', title : '当前值', width: 120
		},{
			field: 'status', title : '状态', width: 50,
			render:function (r) {
				var p = $('<div></div>'), v = r.status;
				return p.text(Cache.sequence.status[r.status]);
			}
		},{
			field: 'id', title : '操作', width: 50,
			render: function(r, tr, gd) {
				var p = $('<div></div>'),
					st = '<span class="a"></span>';
				p.append('&nbsp;');
				$(st).click(function(){
					mac.confirm('确定要 删除 序列 ' + r.code + ' 吗？', function(){
						$.post(App.ctx + '/info/delete.do', {
							id: r.id
						}, function(rs){
							var ro = mac.eval(rs);
							if (ro.success) {
								gd.load();
							} else {
								mac.alert(ro.data, ro.params);
							}
						});
					});
				}).append('删除').appendTo(p);
				return p;
			}
		}
	],
		loader: {
			url: App.ctx + '/info/list.do',
			params: {
				pageNo: 1, pageSize: 20
			},
			autoLoad: true
		},
		pagerLength: 20
	});

	pg.seek('back').click(function(){
		naviName.text('全部序列');
	});
	pg.seek('key').keydown(function(e) {
		if (e.keyCode == 13) {
			gd.load({ key : $(this).val() });
		}
	});
	if (App.logon.power('sequence.info.save')) {
		var p = pg.parent();
		pg.seek('addSequence').click(function(){
			var p = pg.parent();
			App.show({
				title: '添加序列',
				ctx: 'sequence',
				action: 'infoEdit',
				params: {title:'添加序列'}
			}, $.noop, p).show();
		}).show();
	}
	function adjust(){
		var h = pg.parent().height();
		pg.height(h);
		gd.parent().height(h - 68);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="navi">
	<span class="a" name="back">序列管理</span>&gt;&gt;
	<span name="title">XX序列</span>
</div>
<div class="head">
	<button name="addSequence" class="">添加序列</button>
	<input type="text" name="key" class="fr" placeholder="查找" />
</div>
<div class="body">
	<div class="grid"></div>
</div>